export default function rulesHook() {
  // 只能输入数字
  const ageValidate = (rule: any, value: any, callback: any) => {
    if (value) {
      const reg = /^[0-9]*$/;
      if (!reg.test(value)) {
        callback(new Error("只能输入数字"));
      } else {
        callback();
      }
    }
  };
  // 只能输入汉字和点
  const chineseValidate = (rule: any, value: any, callback: any) => {
    if (value) {
      const reg = /^[\u4E00-\u9FA5.]+$/;
      if (!reg.test(value)) {
        callback(new Error("只能输入汉字"));
      } else {
        callback();
      }
    }
  };
  // 最多输入一位小数
  const decimalValidate = (rule: any, value: any, callback: any) => {
    if (value) {
      // const reg = /^[0-9]+([.]{1}[0-9]{1,2})?$/;
      const reg = /^\d+(\.\d)?$/;
      if (!reg.test(value)) {
        callback(new Error("只能输入数字，最多输入一位小数"));
      } else {
        callback();
      }
    }
  };
  // 身份证校验
  const idCardValidate = (rule: any, value: any, callback: any) => {
    if (value) {
      const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      if (!reg.test(value)) {
        callback(new Error("身份证格式不正确"));
      } else {
        callback();
      }
    }
  };
  // 联系电话校验
  const phoneValidate = (rule: any, value: any, callback: any) => {
    if (value) {
      const reg = /^1[3-9]\d{9}$/;
      if (!reg.test(value)) {
        callback(new Error("联系电话格式不正确"));
      } else {
        callback();
      }
    }
  };
  // 表单校验规则
  const rules = {
    // 患者认定单校验规则
    "patientForm.name": [
      { required: true, message: "姓名不能为空", trigger: "blur" },
      { validator: chineseValidate, trigger: "blur" },
    ],
    "patientForm.sex": [
      { required: true, message: "姓别不能为空", trigger: "change" },
    ],
    "patientForm.age": [
      { required: true, message: "年龄不能为空", trigger: "blur" },
    ],
    "patientForm.weight": [
      { required: true, message: "体重不能为空", trigger: "blur" },
      { validator: decimalValidate, trigger: "blur" },
    ],
    "patientForm.idCard": [
      { required: true, message: "身份证号不能为空", trigger: "blur" },
      { validator: idCardValidate, trigger: "blur" },
    ],
    "patientForm.passTime": [
      { required: true, message: "认定通过时间不能为空", trigger: "change" },
    ],
    "patientForm.passPatent": [
      { required: true, message: "认定通过病种不能为空", trigger: "blur" },
    ],
    "patientForm.medicineName": [
      { required: true, message: "药品通用名不能为空", trigger: "change" },
    ],
    "patientForm.dose": [
      { required: true, message: "剂量不能为空", trigger: "blur" },
    ],
    "patientForm.frequency": [
      { required: true, message: "频次不能为空", trigger: "blur" },
    ],
    "patientForm.way": [
      { required: true, message: "给药途径不能为空", trigger: "change" },
    ],
    "patientForm.contactPhone": [
      { required: true, message: "联系电话不能为空", trigger: "blur" },
      { validator: phoneValidate, trigger: "blur" },
    ],
    // 处方字段校验规则
    "prescriptionForm.prescriptionDate": [
      { required: true, message: "处方日期不能为空", trigger: "change" },
    ],
    "prescriptionForm.diagnosis": [
      { required: true, message: "诊断不能为空", trigger: "blur" },
    ],
    "prescriptionForm.medicineName": [
      { required: true, message: "药品通用名不能为空", trigger: "change" },
    ],
    "prescriptionForm.medicineGoodsName": [
      { required: true, message: "药品商品名不能为空", trigger: "change" },
    ],
    "prescriptionForm.dose": [
      { required: true, message: "剂量不能为空", trigger: "blur" },
    ],
    "prescriptionForm.frequency": [
      { required: true, message: "频次不能为空", trigger: "blur" },
    ],
    "prescriptionForm.way": [
      { required: true, message: "给药途径不能为空", trigger: "change" },
    ],
    // 非首次处方字段校验规则

    "notFirstPrescriptionForm.name": [
      { required: true, message: "姓名不能为空", trigger: "blur" },
      { validator: chineseValidate, trigger: "blur" },
    ],
    "notFirstPrescriptionForm.sex": [
      { required: true, message: "姓别不能为空", trigger: "change" },
    ],
    "notFirstPrescriptionForm.age": [
      { required: true, message: "年龄不能为空", trigger: "blur" },
    ],
    "notFirstPrescriptionForm.idCard": [
      { required: true, message: "身份证号不能为空", trigger: "blur" },
      { validator: idCardValidate, trigger: "blur" },
    ],
    "notFirstPrescriptionForm.prescriptionDate": [
      { required: true, message: "处方日期不能为空", trigger: "change" },
    ],
    "notFirstPrescriptionForm.diagnosis": [
      { required: true, message: "诊断不能为空", trigger: "blur" },
    ],
    "notFirstPrescriptionForm.medicineName": [
      { required: true, message: "药品通用名不能为空", trigger: "change" },
    ],
    "notFirstPrescriptionForm.medicineGoodsName": [
      { required: true, message: "药品商品名不能为空", trigger: "change" },
    ],
    "notFirstPrescriptionForm.dose": [
      { required: true, message: "剂量不能为空", trigger: "blur" },
    ],
    "notFirstPrescriptionForm.frequency": [
      { required: true, message: "频次不能为空", trigger: "blur" },
    ],
    "notFirstPrescriptionForm.way": [
      { required: true, message: "给药途径不能为空", trigger: "change" },
    ],
  };
  const wayOptions = [
    {
      label: "口服",
      value: 0,
    },
    {
      label: "静脉注射",
      value: 1,
    },
    {
      label: "皮下注射",
      value: 2,
    },
    {
      label: "肌肉注射",
      value: 3,
    },
    {
      label: "外用",
      value: 4,
    },
    {
      label: "静脉推注",
      value: 5,
    },
    {
      label: "静脉滴注",
      value: 6,
    },
    {
      label: "鞘内注射",
      value: 7,
    },
    {
      label: "动脉灌注",
      value: 8,
    },
    {
      label: "腔内给药",
      value: 9,
    },
    {
      label: "吸入",
      value: 10,
    },
    {
      label: "持续皮下输注",
      value: 11,
    },
    {
      label: "其他",
      value: 12,
    },
  ];
  // 患者认定表信息
  const columnsForPatient = [
    {
      prop: "name",
      label: "姓名",
      placeholder: "请输入姓名",
      type: "input",
      maxlength: 32,
    },
    {
      prop: "sex",
      label: "性别",
      type: "radio",
      options: [
        { label: "男", value: "1" },
        { label: "女", value: "2" },
      ],
    },
    { prop: "age", label: "年龄", type: "input", disabled: true },
    { prop: "weight", label: "体重", placeholder: "请输入体重", type: "input" },
    {
      prop: "idCard",
      label: "身份证号",
      placeholder: "请输入身份证号",
      type: "input",
    },
    {
      prop: "address",
      label: "患者参保地",
      placeholder: "请输入患者参保地",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "orgName",
      label: "认定机构",
      placeholder: "请输入认定机构",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "doctorName",
      label: "认定医生",
      placeholder: "请输入认定医生",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "passTime",
      label: "认定通过时间",
      placeholder: "",
      type: "date",
    },
    {
      prop: "passPatent",
      label: "认定通过病种",
      placeholder: "请输入认定通过病种",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "medicineName",
      label: "药品通用名",
      placeholder: "请选择药品通用名",
      type: "select",
      filterable: true,
    },
    {
      prop: "medicineGoodsName",
      label: "药品商品名",
      placeholder: "请选择药品商品名",
      type: "select",
      filterable: true,
    },
    {
      prop: "dose",
      label: "剂量",
      placeholder: "请输入剂量",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "frequency",
      label: "频次",
      placeholder: "请输入频次",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "way",
      label: "给药途径",
      placeholder: "请选择给药途径",
      type: "select",
      options: wayOptions,
    },
    {
      prop: "contactPhone",
      label: "联系电话",
      placeholder: "请输入联系电话",
      type: "input",
      maxlength: 11,
    },
  ];
  // 处方信息
  const columnsForPrescription = [
    // {
    //   prop: "name",
    //   label: "姓名",
    //   placeholder: "请输入姓名",
    //   type: "input",
    //   maxlength: 32,
    // },
    // {
    //   prop: "sex",
    //   label: "性别",
    //   type: "radio",
    //   options: [
    //     { label: "男", value: "1" },
    //     { label: "女", value: "2" },
    //   ],
    // },
    // { prop: "age", label: "年龄", type: "input", placeholder: "请输入年龄" },
    {
      prop: "prescriptionDate",
      label: "处方日期",
      placeholder: "请选择处方日期",
      type: "date",
    },
    {
      prop: "diagnosis",
      label: "诊断",
      placeholder: "请输入诊断",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "medicineName",
      label: "药品通用名",
      placeholder: "请选择药品通用名",
      type: "select",
      filterable: true,
    },
    {
      prop: "medicineGoodsName",
      label: "药品商品名",
      placeholder: "请选择药品商品名",
      type: "select",
      filterable: true,
    },
    {
      prop: "medicineFactory",
      label: "药品厂家",
      placeholder: "请选择药品厂家",
      type: "select",
      filterable: true,
    },
    {
      prop: "dose",
      label: "剂量",
      placeholder: "请输入剂量",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "frequency",
      label: "频次",
      placeholder: "请输入频次",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "way",
      label: "给药途径",
      placeholder: "请选择给药途径",
      type: "select",
      options: wayOptions,
    },
  ];
  const noFirstColumnsForPrescription = [
    {
      prop: "name",
      label: "姓名",
      placeholder: "请输入姓名",
      type: "input",
      maxlength: 32,
    },
    {
      prop: "sex",
      label: "性别",
      type: "radio",
      options: [
        { label: "男", value: "1" },
        { label: "女", value: "2" },
      ],
    },
    { prop: "age", label: "年龄", type: "input", placeholder: "请输入年龄" },
    {
      prop: "prescriptionDate",
      label: "处方日期",
      placeholder: "请选择处方日期",
      type: "date",
    },
    {
      prop: "diagnosis",
      label: "诊断",
      placeholder: "请输入诊断",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "medicineName",
      label: "药品通用名",
      placeholder: "请选择药品通用名",
      type: "select",
      filterable: true,
    },
    {
      prop: "medicineGoodsName",
      label: "药品商品名",
      placeholder: "请选择药品商品名",
      type: "select",
      filterable: true,
    },
    {
      prop: "medicineFactory",
      label: "药品厂家",
      placeholder: "请选择药品厂家",
      type: "select",
      filterable: true,
    },
    {
      prop: "dose",
      label: "剂量",
      placeholder: "请输入剂量",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "frequency",
      label: "频次",
      placeholder: "请输入频次",
      type: "input",
      maxlength: 64,
    },
    {
      prop: "way",
      label: "给药途径",
      placeholder: "请选择给药途径",
      type: "select",
      options: wayOptions,
      filterable: true,
    },
  ];
  return {
    rules,
    columnsForPatient,
    columnsForPrescription,
    noFirstColumnsForPrescription,
  };
}
